package com.zdpx.pxframework.log.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zdpx.pxframework.log.dto.OperateLogModelDto;
import com.zdpx.pxframework.log.service.OperateLogFrameworkService;
import com.zdpx.pxframework.system.api.api.RemoteOperateLogService;
import com.zdpx.pxframework.system.api.entity.OperateLog;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 操作日志默认实现类
 *
 * @Description:
 * @Author: Cheng XiaoXiao
 * @Date: 2022/5/24 10:04
 */
@Service
public class OperateLogFrameworkServiceImpl implements OperateLogFrameworkService {

    @Resource
    RemoteOperateLogService remoteOperateLogService;

    /**
     * 异步记录操作日志
     *
     * @param reqVO 操作日志对象信息
     */
    @Async
    @Override
    public void createOperateLogAsync(OperateLogModelDto reqVO) {
        //转换为操作日志对象，进行数据保存
        OperateLog operateLog = new OperateLog();
        BeanUtil.copyProperties(reqVO, operateLog);
        operateLog.setStatus(reqVO.getApiStatus());
        operateLog.setType(reqVO.getOperateType());

        remoteOperateLogService.add(operateLog);
    }
}
